package demo02;

import demo02.gun.CalcLexer;
import demo02.gun.CalcParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * Created by Administrator on 2016/6/23.
 *
 */
public class CalcClient {
//    193
//    a = 5
//    b = 6
//    a+b*2
//    a=(1+2)*3
    public static void main(String[] args) throws Exception{
//        InputStream is = args.length > 0 ? new FileInputStream(args[0]) : System.in ;
        InputStream is = new ByteArrayInputStream("(1+2)*3".getBytes()) ;

        ANTLRInputStream input = new ANTLRInputStream(is) ;
        CalcLexer lexer = new CalcLexer(input) ;
        CommonTokenStream token = new CommonTokenStream(lexer) ;
        CalcParser parser = new CalcParser(token);
        ParseTree tree = parser.prog();

//        EvalVisitor eval = new EvalVisitor() ;
//        eval.visit(tree) ; // 开始遍历分析树

        ParseTreeWalker worker = new ParseTreeWalker();
        worker.walk(new DirectiveListener(), tree);

        System.out.println(tree.toStringTree(parser));
    }
}
